package com.arraylist;

import java.util.ArrayList;

public class ArrayTest2 {
    public static void main(String[] args) {
        ArrayList<String> arrayList = new ArrayList<>();
        arrayList.add("a");
        arrayList.add("b");
        arrayList.add("c");
        arrayList.add("d");
        swap(arrayList,1,3);
        System.out.println(arrayList);

    }
    public static void swap(ArrayList<String > arrayList , Integer i ,Integer j) {
        if (i > arrayList.size() || j > arrayList.size()) {
            System.out.println("交表越界");
            return;
        }
        String temp = arrayList.get(i);
        arrayList.set(i,arrayList.get(j));
        arrayList.set(j,temp);

    }




    }

